package com.beiwang2;

import android.os.Build;
import android.util.Log;
import android.widget.Toast;

import androidx.annotation.NonNull;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.ReadableNativeMap;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.WritableNativeArray;
import com.facebook.react.uimanager.IllegalViewOperationException;

import org.json.JSONObject;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class DBManagerModule extends ReactContextBaseJavaModule {
    private static final String TAG = "BeiwangDB";
    private ReactContext mReactContext;

    public DBManagerModule(ReactApplicationContext reactContext) {
        super(reactContext);
        mReactContext = reactContext;
    }
    @NonNull
    @Override
    public String getName() {
        return "DBManagerModule";
    }

    /*查询重要事务[Imptask表]*/
    @ReactMethod
    public void selectImptask(Promise promise){
        ArrayList<Map<String, String>> list;
        DBManager dbManager = new DBManager(mReactContext);
        list = dbManager.selectImptask();
        WritableArray arrRN = Arguments.createArray();
        for (Map<String, String> m:list) {
            JSONObject jsonObj=new JSONObject(m);
            arrRN.pushString(jsonObj.toString());
        }
        try {
            promise.resolve(arrRN);
        } catch (Exception e) {
            promise.reject("500","获取失败");
        }
    }

    /*查询排序重要事务[Imptask表]*/
    @ReactMethod
    public void sortImptask(String type ,Promise promise){
        ArrayList<Map<String, String>> list;
        DBManager dbManager = new DBManager(mReactContext);
        list = dbManager.sortImptask(type);
        WritableArray arrRN = Arguments.createArray();
        for (Map<String, String> m:list) {
            JSONObject jsonObj=new JSONObject(m);
            arrRN.pushString(jsonObj.toString());
        }
        try {
            promise.resolve(arrRN);
        } catch (Exception e) {
            promise.reject("500","获取失败");
        }
    }

    /*保存重要事务[Imptask表]*/
    @ReactMethod
    public void saveImptask(String title, String task, String datetime, String impcode,int alarmid) {
        DBManager dbManager = new DBManager(mReactContext);
        System.out.println(alarmid);
            boolean f = dbManager.saveImptask(title,task,datetime,impcode,alarmid);
            if(f){
                Toast.makeText(getReactApplicationContext(),"添加成功",Toast.LENGTH_LONG).show();
            }else{
                Toast.makeText(getReactApplicationContext(),"添加失败",Toast.LENGTH_LONG).show();
            }
    }

    /*修改重要事务状态[Imptask表]*/
    @ReactMethod
    public void isCheckImptask(int rowid){
        DBManager dbManager = new DBManager(mReactContext);
        dbManager.isCheckImptask(rowid);
    }

    /*修改重要事务状态[Imptask表]*/
    @ReactMethod
    public void delImptask(ReadableArray rowids){
        DBManager dbManager = new DBManager(mReactContext);
        dbManager.delImptask(rowids);
    }

    /*获取重要事务详情[Imptask表]*/
    @ReactMethod
    public void taskdetails(int rowid,Promise promise){
        DBManager dbManager = new DBManager(mReactContext);
        Map<String, String> details = new HashMap<String, String>();
        details = dbManager.taskdetails(rowid);
        JSONObject jsonObj=new JSONObject(details);
        try {
            promise.resolve(jsonObj.toString());
        } catch (Exception e) {
            promise.reject("500","获取失败");
        }
    }

    /*编辑重要事务详情查询*/
    @ReactMethod
    public void editTask(int rowid, String title, String task, String datetime, String impcode,int alarmid){
        DBManager dbManager = new DBManager(mReactContext);
        boolean f = dbManager.editTask(rowid,title,task,datetime,impcode,alarmid);
        if(f){
            Toast.makeText(getReactApplicationContext(),"修改成功",Toast.LENGTH_LONG).show();
        }else{
            Toast.makeText(getReactApplicationContext(),"修改失败",Toast.LENGTH_LONG).show();
        }
    }

    /*保存计划*/
    @ReactMethod
    public void addPlan(String title,String detail,ReadableArray imgUri){
        DBManager dbManager = new DBManager(mReactContext);
        boolean f = dbManager.addPlan(title, detail,imgUri);
        if(f){
            Toast.makeText(getReactApplicationContext(),"添加成功",Toast.LENGTH_LONG).show();
        }else{
            Toast.makeText(getReactApplicationContext(),"添加失败",Toast.LENGTH_LONG).show();
        }
    }

    /*查询计划*/
    @ReactMethod
    public void selectPlan(int state,String str,Promise promise){
        ArrayList<Map<String, String>> list;
        DBManager dbManager = new DBManager(mReactContext);
        list = dbManager.selectPlan(state,str);
        WritableArray arrRN = Arguments.createArray();
        for (Map<String, String> m:list) {
            JSONObject jsonObj=new JSONObject(m);
            arrRN.pushString(jsonObj.toString());
        }
        try {
            promise.resolve(arrRN);
        } catch (Exception e) {
            promise.reject("500","获取失败");
        }
    }

    /*计划详情*/
    @ReactMethod
    public void planDetail(int planId,Promise promise){
        DBManager dbManager = new DBManager(mReactContext);
        Map<String, String> details = new HashMap<String, String>();
        details = dbManager.planDetail(planId);
        System.out.println(details);
        JSONObject jsonObj=new JSONObject(details);
        try {
            promise.resolve(jsonObj.toString());
        } catch (Exception e) {
            promise.reject("500","获取失败");
        }
    }
    /*删除计划*/
    @ReactMethod
    public void delPlan(int planid){
        DBManager dbManager = new DBManager(mReactContext);
        boolean f = dbManager.delPlan(planid);
        if(f){
            Toast.makeText(getReactApplicationContext(),"已删除",Toast.LENGTH_LONG).show();
        }else{
            Toast.makeText(getReactApplicationContext(),"删除失败",Toast.LENGTH_LONG).show();
        }
    }

    /*编辑计划*/
    @ReactMethod
    public void editPlan(int planId,String title,String detail,ReadableArray imgUri){
        DBManager dbManager = new DBManager(mReactContext);
        boolean f = dbManager.editPlan(planId,title, detail,imgUri);
        if(f){
            Toast.makeText(getReactApplicationContext(),"添加成功",Toast.LENGTH_LONG).show();
        }else{
            Toast.makeText(getReactApplicationContext(),"添加失败",Toast.LENGTH_LONG).show();
        }
    }

    /*改变计划状态*/
    @ReactMethod
    public void changePlanState(int planId,int state){
        DBManager dbManager = new DBManager(mReactContext);
        boolean f = dbManager.changePlanState(planId,state);
        if(f){
            if(state==1){
                Toast.makeText(getReactApplicationContext(),"进入就绪区的任务就要尽快执行^v^",Toast.LENGTH_LONG).show();
            }
            if(state==2){
                Toast.makeText(getReactApplicationContext(),"已暂停任务",Toast.LENGTH_LONG).show();
            }
            if(state==3){
                Toast.makeText(getReactApplicationContext(),"准备验收",Toast.LENGTH_LONG).show();
            }
            if(state==4){
                Toast.makeText(getReactApplicationContext(),"您完成了一项任务",Toast.LENGTH_LONG).show();
            }
        }else{
            Toast.makeText(getReactApplicationContext(),"更新失败",Toast.LENGTH_LONG).show();
        }
    }

    /*开始事务*/
    @ReactMethod
    public void startPlan(int planId, String startTime, String planTime, double planWorkTime){
        DBManager dbManager = new DBManager(mReactContext);
        boolean f = dbManager.startPlan(planId,startTime,planTime,planWorkTime);
        if(f){
            Toast.makeText(getReactApplicationContext(),"开始执行",Toast.LENGTH_LONG).show();
        }else{
            Toast.makeText(getReactApplicationContext(),"执行失败",Toast.LENGTH_LONG).show();
        }
    }

    /*更新工作时长*/
    @ReactMethod
    public void updateWorkTime(int planId,double workTime){
        DBManager dbManager = new DBManager(mReactContext);
        boolean f = dbManager.updateWorkTime(planId,workTime);
        if(f){
            Toast.makeText(getReactApplicationContext(),"已工作"+workTime+"小时",Toast.LENGTH_LONG).show();
        }else{
            Toast.makeText(getReactApplicationContext(),"更新失败",Toast.LENGTH_LONG).show();
        }
    }

    /*更新结束时间*/
    @ReactMethod
    public void updateEndTime(int planId,String endTime){
        DBManager dbManager = new DBManager(mReactContext);
        boolean f = dbManager.updateEndTime(planId,endTime);
        if(!f){
            Toast.makeText(getReactApplicationContext(),"更新失败",Toast.LENGTH_LONG).show();
        }
    }

    /*计划完成详情*/
    @ReactMethod
    public void compDetail(int planId,Promise promise){
        DBManager dbManager = new DBManager(mReactContext);
        Map<String, String> details = new HashMap<String, String>();
        details = dbManager.compDetail(planId);
        JSONObject jsonObj=new JSONObject(details);
        try {
            promise.resolve(jsonObj.toString());
        } catch (Exception e) {
            promise.reject("500","获取失败");
        }
    }

    /*添加验收报告*/
    @ReactMethod
    public void saveReport(int planid,String title,String report,ReadableArray fileurls,String complete_time){
        DBManager dbManager = new DBManager(mReactContext);
        boolean f = dbManager.saveReport(planid,title,report,fileurls,complete_time);
        if(!f){
            Toast.makeText(getReactApplicationContext(),"添加失败",Toast.LENGTH_LONG).show();
        }
    }

    /*获得验收报告*/
    @ReactMethod
    public void selectAccReport(Promise promise){
        ArrayList<Map<String, String>> list;
        DBManager dbManager = new DBManager(mReactContext);
        list = dbManager.selectAccReport();
        WritableArray arrRN = Arguments.createArray();
        for (Map<String, String> m:list) {
            JSONObject jsonObj=new JSONObject(m);
            arrRN.pushString(jsonObj.toString());
        }
        try {
            promise.resolve(arrRN);
        } catch (Exception e) {
            promise.reject("500","获取失败");
        }
    }

    /*获得验收报告*/
    @ReactMethod
    public void getReportCount(Promise promise){
        int count=0;
        DBManager dbManager = new DBManager(mReactContext);
        count = dbManager.getReportCount();
        try {
            promise.resolve(count);
        } catch (Exception e) {
            promise.reject("500","获取失败");
        }
    }

    /*获得验收报告详情*/
    @ReactMethod
    public void AccDetail(int id,Promise promise){
        DBManager dbManager = new DBManager(mReactContext);
        Map<String, String> details = new HashMap<String, String>();
        details = dbManager.accDetail(id);
        JSONObject jsonObj=new JSONObject(details);
        try {
            promise.resolve(jsonObj.toString());
        } catch (Exception e) {
            promise.reject("500","获取失败");
        }
    }

    /*编辑验收报告*/
    @ReactMethod
    public void editReport(int id,String report,ReadableArray fileurls){
        DBManager dbManager = new DBManager(mReactContext);
        boolean f = dbManager.editReport(id,report,fileurls);
        if (f) {
            Toast.makeText(getReactApplicationContext(),"编辑成功",Toast.LENGTH_LONG).show();
        }else {
            Toast.makeText(getReactApplicationContext(),"编辑失败",Toast.LENGTH_LONG).show();
        }
    }

    /*删除验收报告*/
    @ReactMethod
    public void delReport(int id){
        DBManager dbManager = new DBManager(mReactContext);
        boolean f = dbManager.delReport(id);
        if (f) {
            Toast.makeText(getReactApplicationContext(),"删除成功",Toast.LENGTH_LONG).show();
        }else {
            Toast.makeText(getReactApplicationContext(),"删除失败",Toast.LENGTH_LONG).show();
        }
    }

    /*创建笔记本*/
    @ReactMethod
     public void createNoteBook(String name,String coveruri,ReadableArray tag) {
        DBManager dbManager = new DBManager(mReactContext);
        boolean f = dbManager.createNoteBook(name,coveruri,tag);
        if(f){
            Toast.makeText(getReactApplicationContext(),"创建成功",Toast.LENGTH_LONG).show();
        }else{
            Toast.makeText(getReactApplicationContext(),"创建失败",Toast.LENGTH_LONG).show();
        }
    }

    /*得到笔记本*/
    @ReactMethod
    public void selectNoteBook(String str,Promise promise){
        ArrayList<Map<String, String>> list;
        DBManager dbManager = new DBManager(mReactContext);
        list = dbManager.selectNoteBook(str);
        WritableArray arrRN = Arguments.createArray();
        for (Map<String, String> m:list) {
            JSONObject jsonObj=new JSONObject(m);
            arrRN.pushString(jsonObj.toString());
        }
        try {
            promise.resolve(arrRN);
        } catch (Exception e) {
            promise.reject("500","获取失败");
        }
    }

    /*创建笔记表*/
    @ReactMethod
    public void createNoteTable(int bookid){
        DBManager dbManager = new DBManager(mReactContext);
        dbManager.createNoteTable(bookid);
    }

    /*编辑笔记本*/
    @ReactMethod
    public void editNoteBook(int bookid,String name,String coveruri,ReadableArray tag){
        DBManager dbManager = new DBManager(mReactContext);
        boolean f = dbManager.editNoteBook(bookid,name,coveruri,tag);
        if (f) {
            Toast.makeText(getReactApplicationContext(),"编辑成功",Toast.LENGTH_LONG).show();
        }else {
            Toast.makeText(getReactApplicationContext(),"编辑失败",Toast.LENGTH_LONG).show();
        }
    }

    /*获得笔记本详情*/
    @ReactMethod
    public void noteBookDetail(int bookid,Promise promise){
        DBManager dbManager = new DBManager(mReactContext);
        Map<String, String> details = new HashMap<String, String>();
        details = dbManager.noteBookDetail(bookid);
        JSONObject jsonObj=new JSONObject(details);
        try {
            promise.resolve(jsonObj.toString());
        } catch (Exception e) {
            promise.reject("500","获取失败");
        }
    }

    /*删除笔记本*/
    @ReactMethod
    public void delNoteBook(int bookid){
        DBManager dbManager = new DBManager(mReactContext);
        boolean f = dbManager.delNoteBook(bookid);
        if (f) {
            Toast.makeText(getReactApplicationContext(),"删除成功",Toast.LENGTH_LONG).show();
        }else {
            Toast.makeText(getReactApplicationContext(),"删除失败",Toast.LENGTH_LONG).show();
        }
    }

    /*创建笔记*/
    @ReactMethod
    public void saveNote(String title, String detail, ReadableArray imgUri,String voiceurl,int bookid){
        DBManager dbManager = new DBManager(mReactContext);
        boolean f = dbManager.saveNote(title,detail,imgUri,voiceurl,bookid);
        if (f) {
            Toast.makeText(getReactApplicationContext(),"创建成功",Toast.LENGTH_LONG).show();
        }else {
            Toast.makeText(getReactApplicationContext(),"创建失败",Toast.LENGTH_LONG).show();
        }
    }

    /*得到笔记*/
    @ReactMethod
    public void selectNotes(int bookid,Promise promise){
        ArrayList<Map<String, String>> list;
        DBManager dbManager = new DBManager(mReactContext);
        list = dbManager.selectNotes(bookid);
        WritableArray arrRN = Arguments.createArray();
        for (Map<String, String> m:list) {
            JSONObject jsonObj=new JSONObject(m);
            arrRN.pushString(jsonObj.toString());
        }
        try {
            promise.resolve(arrRN);
        } catch (Exception e) {
            promise.reject("500","获取失败");
        }
    }

    /*删除回收站笔记*/
    @ReactMethod
    public void delNoteBin(int id){
        DBManager dbManager = new DBManager(mReactContext);
        dbManager.delNoteBin(id);
    }

    /*获得笔记详情*/
    @ReactMethod
    public void noteDetail(int noteid,int bookid,Promise promise){
        DBManager dbManager = new DBManager(mReactContext);
        Map<String, String> details = new HashMap<String, String>();
        details = dbManager.noteDetail(noteid,bookid);
        JSONObject jsonObj=new JSONObject(details);
        try {
            promise.resolve(jsonObj.toString());
        } catch (Exception e) {
            promise.reject("500","获取失败");
        }
    }

    /*编辑笔记*/
    @ReactMethod
    public void editNote(String title, String detail, ReadableArray imgUri,String voiceurl,int noteid,int bookid){
        DBManager dbManager = new DBManager(mReactContext);
        boolean f = dbManager.editNote(title,detail,imgUri,voiceurl,noteid,bookid);
        if (f) {
            Toast.makeText(getReactApplicationContext(),"编辑成功",Toast.LENGTH_LONG).show();
        }else {
            Toast.makeText(getReactApplicationContext(),"编辑失败",Toast.LENGTH_LONG).show();
        }
    }

    /*还原笔记*/
    @ReactMethod
    public void restoreNote(int id ,int noteid,int bookid){
        DBManager dbManager = new DBManager(mReactContext);
        boolean f = dbManager.restoreNote(id,noteid,bookid);
        if (f) {
            Toast.makeText(getReactApplicationContext(),"已还原",Toast.LENGTH_LONG).show();
        }else {
            Toast.makeText(getReactApplicationContext(),"还原失败",Toast.LENGTH_LONG).show();
        }
    }

    /*添加到回收站*/
    @ReactMethod
    public void moveToRecycle(int noteid,int bookid,String title){
        DBManager dbManager = new DBManager(mReactContext);
        boolean f = dbManager.moveToRecycle(noteid,bookid,title);
        if (f) {
            Toast.makeText(getReactApplicationContext(),"已移动至回收站",Toast.LENGTH_LONG).show();
        }else {
            Toast.makeText(getReactApplicationContext(),"移动失败",Toast.LENGTH_LONG).show();
        }
    }

    /*删除笔记*/
    @ReactMethod
    public void delNote(int noteid,int bookid){
        DBManager dbManager = new DBManager(mReactContext);
        boolean f = dbManager.delNote(noteid,bookid);
        if (f) {
            Toast.makeText(getReactApplicationContext(),"删除成功",Toast.LENGTH_LONG).show();
        }else {
            Toast.makeText(getReactApplicationContext(),"删除失败",Toast.LENGTH_LONG).show();
        }
    }

    /*搜索笔记*/
    @ReactMethod
    public void searchNote(String str,int bookid,Promise promise){
        ArrayList<Map<String, String>> list;
        DBManager dbManager = new DBManager(mReactContext);
        list = dbManager.searchNote(str,bookid);
        WritableArray arrRN = Arguments.createArray();
        for (Map<String, String> m:list) {
            JSONObject jsonObj=new JSONObject(m);
            arrRN.pushString(jsonObj.toString());
        }
        try {
            promise.resolve(arrRN);
        } catch (Exception e) {
            promise.reject("500","获取失败");
        }
    }

    /*获得回收笔记*/
    @ReactMethod
    public void selectNoteBin(Promise promise){
        ArrayList<Map<String, String>> list;
        DBManager dbManager = new DBManager(mReactContext);
        list = dbManager.selectNoteBin();
        WritableArray arrRN = Arguments.createArray();
        for (Map<String, String> m:list) {
            JSONObject jsonObj=new JSONObject(m);
            arrRN.pushString(jsonObj.toString());
        }
        try {
            promise.resolve(arrRN);
        } catch (Exception e) {
            promise.reject("500","获取失败");
        }
    }

    /*添加日志*/
    @ReactMethod
    public void saveMineLog(String workname,String work, String unfinished,String problem,
                           ReadableArray imgurls,ReadableArray fileurls,String time){
        DBManager dbManager = new DBManager(mReactContext);
        boolean f = dbManager.saveMineLog(workname,work
                ,unfinished,problem,imgurls,fileurls,time);
        if (f) {
            Toast.makeText(getReactApplicationContext(),"添加成功",Toast.LENGTH_LONG).show();
        }else {
            Toast.makeText(getReactApplicationContext(),"添加失败",Toast.LENGTH_LONG).show();
        }
    }

    /*获得日志*/
    @ReactMethod
    public void selectMineLog(Promise promise){
        ArrayList<Map<String, String>> list;
        DBManager dbManager = new DBManager(mReactContext);
        list = dbManager.selectMineLog();
        WritableArray arrRN = Arguments.createArray();
        for (Map<String, String> m:list) {
            JSONObject jsonObj=new JSONObject(m);
            arrRN.pushString(jsonObj.toString());
        }
        try {
            promise.resolve(arrRN);
        } catch (Exception e) {
            promise.reject("500","获取失败");
        }
    }

    /*获得笔记详情*/
    @ReactMethod
    public void logDetail(int id,Promise promise){
        DBManager dbManager = new DBManager(mReactContext);
        Map<String, String> details = new HashMap<String, String>();
        details = dbManager.logDetail(id);
        JSONObject jsonObj=new JSONObject(details);
        try {
            promise.resolve(jsonObj.toString());
        } catch (Exception e) {
            promise.reject("500","获取失败");
        }
    }

    /*编辑笔记*/
    @ReactMethod
    public void editLog(int id,
                        String workname,String work,String unfinished,
                        String problem,ReadableArray imgurls,
                        ReadableArray fileurls,String time){
        DBManager dbManager = new DBManager(mReactContext);
        boolean f = dbManager.editLog(id,workname,work,unfinished,problem,imgurls,fileurls,time);
        if (f) {
            Toast.makeText(getReactApplicationContext(),"编辑成功",Toast.LENGTH_LONG).show();
        }else {
            Toast.makeText(getReactApplicationContext(),"编辑失败",Toast.LENGTH_LONG).show();
        }
    }

    /*删除笔记*/
    @ReactMethod
    public void delLog(int id){
        DBManager dbManager = new DBManager(mReactContext);
        boolean f = dbManager.delLog(id);
        if (f) {
            Toast.makeText(getReactApplicationContext(),"删除成功",Toast.LENGTH_LONG).show();
        }else {
            Toast.makeText(getReactApplicationContext(),"删除失败",Toast.LENGTH_LONG).show();
        }
    }

    /*获得笔记详情*/
    @ReactMethod
    public void mineLog(Promise promise){
        DBManager dbManager = new DBManager(mReactContext);
        Map<String, String> info = new HashMap<String, String>();
        info = dbManager.mineLog();
        JSONObject jsonObj=new JSONObject(info);
        try {
            promise.resolve(jsonObj.toString());
        } catch (Exception e) {
            promise.reject("500","获取失败");
        }
    }

    /*获得每日信息*/
    @ReactMethod
    public void selectDaily(String date,Promise promise){
        ArrayList<Map<String, String>> list;
        DBManager dbManager = new DBManager(mReactContext);
        list = dbManager.selectDaily(date);
        WritableArray arrRN = Arguments.createArray();
        for (Map<String, String> m:list) {
            JSONObject jsonObj=new JSONObject(m);
            arrRN.pushString(jsonObj.toString());
        }
        try {
            promise.resolve(arrRN);
        } catch (Exception e) {
            promise.reject("500","获取失败");
        }
    }

    /*更新用户总工作时长*/
    @ReactMethod
    public void updateUserWorkTime(double time){
        DBManager dbManager = new DBManager(mReactContext);
        dbManager.updateUserWorkTime(time);
    }

    /*更新用户使用天数*/
    @ReactMethod
    public void updateUserDay(String date){
        DBManager dbManager = new DBManager(mReactContext);
        dbManager.updateUserDay(date);
    }

    /*更新超时记录*/
    @ReactMethod
    public void updateTimeout(int planid){
        DBManager dbManager = new DBManager(mReactContext);
        dbManager.updateTimeout(planid);
    }

    /*获得重要事务统计*/
    @ReactMethod
    public void impTypeCount(Promise promise){
        ArrayList<Map<String, Object>> list;
        DBManager dbManager = new DBManager(mReactContext);
        list = dbManager.impTypeCount();
        WritableArray arrRN = Arguments.createArray();
        for (Map<String, Object> m:list) {
            JSONObject jsonObj=new JSONObject(m);
            arrRN.pushString(jsonObj.toString());
        }
        try {
            promise.resolve(arrRN);
        } catch (Exception e) {
            promise.reject("500","获取失败");
        }
    }

    /*获得用户信息*/
    @ReactMethod
    public void selectUser(Promise promise){
        DBManager dbManager = new DBManager(mReactContext);
        Map<String, String> info = new HashMap<String, String>();
        info = dbManager.selectUser();
        JSONObject jsonObj=new JSONObject(info);
        try {
            promise.resolve(jsonObj.toString());
        } catch (Exception e) {
            promise.reject("500","获取失败");
        }
    }

    /*查询超时任务*/
    @ReactMethod
    public void timeoutTask(Promise promise){
        ArrayList<Map<String, String>> list;
        DBManager dbManager = new DBManager(mReactContext);
        list = dbManager.timeoutTask();
        WritableArray arrRN = Arguments.createArray();
        for (Map<String, String> m:list) {
            JSONObject jsonObj=new JSONObject(m);
            arrRN.pushString(jsonObj.toString());
        }
        try {
            promise.resolve(arrRN);
        } catch (Exception e) {
            promise.reject("500","获取失败");
        }
    }

    /*查询紧急事务*/
    @ReactMethod
    public void exigency(Promise promise){
        ArrayList<Map<String, String>> list;
        DBManager dbManager = new DBManager(mReactContext);
        list = dbManager.exigency();
        WritableArray arrRN = Arguments.createArray();
        for (Map<String, String> m:list) {
            JSONObject jsonObj=new JSONObject(m);
            arrRN.pushString(jsonObj.toString());
        }
        try {
            promise.resolve(arrRN);
        } catch (Exception e) {
            promise.reject("500","获取失败");
        }
    }

    /*添加到报告回收站*/
    @ReactMethod
    public void moveToRpBin(int rpid,String title){
        DBManager dbManager = new DBManager(mReactContext);
        boolean f = dbManager.moveToRpBin(rpid,title);
        if (f) {
            Toast.makeText(getReactApplicationContext(),"已移动至回收站",Toast.LENGTH_LONG).show();
        }else {
            Toast.makeText(getReactApplicationContext(),"移动失败",Toast.LENGTH_LONG).show();
        }
    }

    /*添加到报告回收站*/
    @ReactMethod
    public void moveToLogBin(int logid,String title){
        DBManager dbManager = new DBManager(mReactContext);
        boolean f = dbManager.moveToLogBin(logid,title);
        if (f) {
            Toast.makeText(getReactApplicationContext(),"已移动至回收站",Toast.LENGTH_LONG).show();
        }else {
            Toast.makeText(getReactApplicationContext(),"移动失败",Toast.LENGTH_LONG).show();
        }
    }

    /*删除回收站报告*/
    @ReactMethod
    public void delRpBin(int id){
        DBManager dbManager = new DBManager(mReactContext);
        dbManager.delRpBin(id);
    }

    /*删除回收站日志*/
    @ReactMethod
    public void delLogBin(int id){
        DBManager dbManager = new DBManager(mReactContext);
        dbManager.delLogBin(id);
    }

    /*查询回收报告*/
    @ReactMethod
    public void selectRpBin(Promise promise){
        ArrayList<Map<String, String>> list;
        DBManager dbManager = new DBManager(mReactContext);
        list = dbManager.selectRpBin();
        WritableArray arrRN = Arguments.createArray();
        for (Map<String, String> m:list) {
            JSONObject jsonObj=new JSONObject(m);
            arrRN.pushString(jsonObj.toString());
        }
        try {
            promise.resolve(arrRN);
        } catch (Exception e) {
            promise.reject("500","获取失败");
        }
    }

    /*查询回收日志*/
    @ReactMethod
    public void selectLogBin(Promise promise){
        ArrayList<Map<String, String>> list;
        DBManager dbManager = new DBManager(mReactContext);
        list = dbManager.selectLogBin();
        WritableArray arrRN = Arguments.createArray();
        for (Map<String, String> m:list) {
            JSONObject jsonObj=new JSONObject(m);
            arrRN.pushString(jsonObj.toString());
        }
        try {
            promise.resolve(arrRN);
        } catch (Exception e) {
            promise.reject("500","获取失败");
        }
    }

    /*还原报告*/
    @ReactMethod
    public void restoreReport(int id ,int rpid){
        DBManager dbManager = new DBManager(mReactContext);
        boolean f = dbManager.restoreReport(id,rpid);
        if (f) {
            Toast.makeText(getReactApplicationContext(),"已还原",Toast.LENGTH_LONG).show();
        }else {
            Toast.makeText(getReactApplicationContext(),"还原失败",Toast.LENGTH_LONG).show();
        }
    }

    /*还原日志*/
    @ReactMethod
    public void restoreLog(int id ,int logid){
        DBManager dbManager = new DBManager(mReactContext);
        boolean f = dbManager.restoreLog(id,logid);
        if (f) {
            Toast.makeText(getReactApplicationContext(),"已还原",Toast.LENGTH_LONG).show();
        }else {
            Toast.makeText(getReactApplicationContext(),"还原失败",Toast.LENGTH_LONG).show();
        }
    }

    /*设置标语*/
    @ReactMethod
    public void editSlogan(String slogan){
        DBManager dbManager = new DBManager(mReactContext);
        boolean f = dbManager.editSlogan(slogan);
        if (f) {
            Toast.makeText(getReactApplicationContext(),"已更新标语",Toast.LENGTH_LONG).show();
        }else {
            Toast.makeText(getReactApplicationContext(),"更新失败",Toast.LENGTH_LONG).show();
        }
    }

    /*设置备注*/
    @ReactMethod
    public void addMark(String note,int id){
        DBManager dbManager = new DBManager(mReactContext);
        boolean f = dbManager.addMark(note,id);
        if (f) {
            Toast.makeText(getReactApplicationContext(),"更新成功",Toast.LENGTH_LONG).show();
        }else {
            Toast.makeText(getReactApplicationContext(),"更新失败",Toast.LENGTH_LONG).show();
        }
    }
}
